/*
 * @Author: your name
 * @Date: 2020-09-12 11:03:18
 * @LastEditTime: 2020-09-22 14:13:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \PipeOneMap_WebClient\src\app\shared\components\pages-card\pages-card.component.ts
 */
import { Component, OnInit, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';

@Component({
  selector: 'app-pages-card',
  templateUrl: './pages-card.component.html',
  styleUrls: ['./pages-card.component.scss']
})
export class PagesCardComponent implements OnInit, OnChanges {

  // 初始化！
  @Input() pagedata = null;
  @Output() pageparams = new EventEmitter<any>();
  pageIndex = 1;
  pageSize = 5;
  total = 0;
  id = null;

  constructor() { }

  ngOnInit() {
    // this.total = this.pagedata.totalCount;
    // this.id = this.pagedata.id;
  }

  // 往外传值！(接收数据呢？)
  pageIndexChange(e) {
    const params = {
      pageIndex: e,
      pageSize: this.pageSize,
      id: this.id
    };
    // 拿着这个参数去获取数据！
    this.pageparams.emit(params);
  }

  pageSizeChange(e) {
    this.pageIndex = 1;
    const params = {
      pageIndex: this.pageIndex,
      pageSize: e,
      id: this.id
    };
    // 将其作为请求参数去请求数据！
    this.pageparams.emit(params);
  }

  ngOnChanges(changes: SimpleChanges) {
    if (changes && changes.pagedata.currentValue) {
     // console.log(66, changes.pagedata.currentValue.pageNo);
      this.pageIndex = changes.pagedata.currentValue.pageNo;
      this.pagedata = changes.pagedata.currentValue;
      // this.total = changes.pagedata.currentValue.totalCount;
      this.id = changes.pagedata.currentValue.id;
    }
  }
}
